package com.front;

import com.admin.service.FeeService;
import com.admin.entity.Fee;
import com.admin.sys.utils.jwt.JwtUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;
import com.admin.sys.utils.admin.StringUtils;
import javax.servlet.http.HttpServletRequest;
import com.admin.sys.base.module.extend.web.BaseController;
import com.admin.sys.base.entity.ResultInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
*【费用信息】管理
*/
@RestController
@RequestMapping("/api/fee")
public class ApiFeeController extends BaseController {

    @Autowired
    private FeeService feeService;

    /**
     *【费用信息】获取分页数据
     */
    @RequestMapping("/getPage")
    public ResultInfo getPage(Page<Fee> page, Fee fee) {
        fee.setRegisterId(JwtUtils.getCurrentUserId());
        IPage<Fee> iPage = feeService.getPage(page, fee);
        return ResultInfo.ok("获取分页成功",iPage);
    }

    /**
    * 【费用信息】获取列表数据
    */
    @RequestMapping("/getList")
    public ResultInfo getList(Fee fee) {
        List<Fee> list = feeService.getList(fee);
        return ResultInfo.ok("获取列表成功", list);
    }

    /**
    *【费用信息】根据对象数据
    */
    @RequestMapping("/get")
    public ResultInfo get(Fee fee) {
        Fee entity = feeService.get(fee);
        return ResultInfo.ok("获取成功",entity);
    }

    /**
     *【费用信息】保存或修改
     */
    @RequestMapping("/sub")
    public ResultInfo saveOrUpdate(HttpServletRequest request,Fee fee){
        try {
            if(StringUtils.isEmpty(fee.getId())){
                feeService.insert(fee);//新增
                return ResultInfo.ok("保存成功！");
            }else{
                feeService.update(fee);//修改
                return ResultInfo.ok("修改成功！");
            }
        } catch (Exception e) {
            return ResultInfo.error("保存失败！失败信息:"+e.getMessage());
        }
    }

    /**
     *【费用信息】根据id删除
     */
    @RequestMapping("/delete")
    public ResultInfo delete(HttpServletRequest request, Fee fee) {
        feeService.delete(fee.getId());
        return ResultInfo.ok("删除成功！");
    }

    /**
    * 【费用信息】批量删除
    */
    @RequestMapping("/delAll")
    public ResultInfo delAll(String[] ids) {
        feeService.delAll(ids);
        return ResultInfo.ok("批量删除成功！");
    }

}



